<?php

namespace Common\Lib\Payments\AlipayDirect;

/**
 * @class direct_alipay
 * @brief 支付宝插件类
 */
class AlipayDirect {

    public $instance;

    public function __construct($payment, $backParam) {

        if (I('get._wap', 0, 'int') || $this->isMobile()) {
            include_once 'AlipayDirectMobile.class.php';
            $this->instance = new AlipayDirectMobile($payment, $backParam);
        } else {
            include_once 'AlipayDirectPC.class.php';
            $this->instance = new AlipayDirectPC($payment, $backParam);
        }
    }

    protected function isMobile() {
        if (stristr($_SERVER['HTTP_VIA'], "wap")) {
            return true;
        } elseif (strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML") > 0) {
            return true;
        } elseif (preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])) {
            return true;
        } else {
            return false;
        }
    }

    public function __get($name) {
        return $this->instance->$name;
    }

    public function __set($name, $value) {
        $this->instance->$name = $value;
    }

    public function __call($name, $arguments) {
        return call_user_method_array($name, $this->instance, $arguments);
    }

    /**
     * @param 获取配置参数
     */
    public function configParam() {
        $result = array(
            'M_PartnerId' => '合作者身份（PID）',
            'M_PartnerKey' => '安全校验码（Key）',
            'M_Email' => '绑定账号(邮箱，手机号)',
        );
        return $result;
    }

}
